<?php
_import("ImportData.class.php");
_import("HeadCol.php");
_lib("Session");
class DebugController extends BaseController {
	
	// 导入automobile单行数据
	protected function importRow(&$data) {
		$loader = new ImportData();
		$brand_id = $loader->importBrand($data["MAKE_NAME"], $data["FIRST_LETTER"]);
		$maker_id = $loader->importMaker($data["MODEL_SERIES"], $brand_id);
		$series_id = $loader->importSeries($data["MODEL_NAME"], $maker_id);
		$country_id = $loader->importCountry($data["COUNTRY"]);
		$mobiletype_id = $loader->importMobileType($data["TYPE_SERIES"]);
		$technology_id = $loader->importTechnology($data["TECHNOLOGY"]);
		$class_id = $loader->importClass($data["VEHICLE_CLASS"]);
		$transmission_id = $loader->importTransmission($data["TRANSMISSION"]);
		
		return $loader->importAutoMobile($data["TYPE_NAME"], $mobiletype_id, 
				$country_id, $technology_id, $class_id, $data["ENGINE_CAPACITY"], 
				"", $transmission_id, "2000", 
				"2014", $brand_id, $maker_id, $series_id);
	}
	
	// 导入多行数据
	protected function importMultiRow(&$data, $rows) {	
		for($i = 0; $i < $rows; $i++) {
			$this->importRow($data[$i]);
		}
	}
	
	// 导入automobile测试
	public function importTAction() {
		$tModel = new TModel();
		$cnt = 24228;			
		$times = intval($cnt / 1000);	// 导入1000条的次数
		$last = $cnt % 1000;			// 最后剩余多少
		
		for($i = 0; $i < $times; $i++) {
			$data = $tModel->assocAll(null, null, 1000, $i * 1000);
			$this->importMultiRow($data, 1000);
		}
		$data = $tModel->assocAll(null, null, $last, intval($times * 1000));
		$this->importMultiRow($data, $last);
	}
	
	// 清空测试
	public function clearTAction() {
		$testTabs = array(
				"t_country", "t_automobile", "t_class",
				"t_brand", "t_maker", "t_series",
				"t_mobiletype", "t_technology",
				"t_transmission", 
		);
			
		$model = new BaseModel();
		foreach($testTabs as $tab) {
			$model->adapter()->query("TRUNCATE TABLE ".$tab);
		}
	}
	
	public function checktableAction() {
		$_POST =  array("username"=>"newton", "password"=>"password", "c"=>"index");
		_print($_POST, "POST");
		$userModel = new UserModel;
		$userModel->create();
		
	}
	
	public function attrheadAction() {
		$headcolUtil = new HeadCol();
		$data = $headcolUtil->getAttrHead(1);
		_print($data);
		
	}
	
	
	public function codetransmitAction() {
		
	}
	
	public function sqlFuncAction() {
		$model = new BaseModel();
		$sql = "CALL getMobileInfo(1)";
		$res = $model->adapter()->query($sql);
		$result = $model->adapter()->fetch_array($res);
		_print($result);
	}
	
	// 测试系统库
	public function testLibAction() {
		
	}
	
}